package cn.alcatraz.system.controller;

import cn.alcatraz.basic.utils.AjaxResult;
import cn.alcatraz.basic.utils.PageList;
import cn.alcatraz.system.domain.SystemDictionaryDetail;
import cn.alcatraz.system.query.SystemDictionaryDetailQuery;
import cn.alcatraz.system.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemDictionaryDetail")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;


    /**
     * @Title: loadAll
     * @Description: 获取全部部门数据
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/24 19:42
     * @Parameters:
     * @Return
     */
    @GetMapping
    public List<SystemDictionaryDetail> loadAll() {
        return systemDictionaryDetailService.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 通过id获取部门数据
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/24 19:43
     * @Parameters:
     * @Return
     */
    @GetMapping("/{id}")
    public SystemDictionaryDetail loadById(@PathVariable("id") Long id) {
        return systemDictionaryDetailService.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: 通过id删除部门数据
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/24 19:46
     * @Parameters:
     * @Return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        try {
            systemDictionaryDetailService.removeById(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试!");
        }
    }

    /**
     * @Title: edit
     * @Description: 部门添加或修改数据
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/24 19:55
     * @Parameters:
     * @Return
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SystemDictionaryDetail systemDictionaryDetail) { // @RequestBody：将请求body中的json数据转换为对象
        try {
            if (systemDictionaryDetail.getId() == null) {
                systemDictionaryDetailService.save(systemDictionaryDetail);
            } else {
                systemDictionaryDetailService.updateById(systemDictionaryDetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试!");
        }
    }

    /**
     * @Title: query
     * @Description: 高级查询和分页数据
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/24 19:56
     * @Parameters:
     * @Return
     */
    @PostMapping
    public PageList<SystemDictionaryDetail> query(@RequestBody SystemDictionaryDetailQuery systemDictionaryDetailQuery) { // @RequestBody：将请求body中的json数据转换为对象
        return systemDictionaryDetailService.queryT(systemDictionaryDetailQuery);
    }

    /**
     * @Title: patchRemove
     * @Description: 批量删除
     * @Author: TinyYu
     * @Version: 1.0
     * @Date:  2022/6/25 11:26
     * @Parameters:
     * @Return
     */
    @PatchMapping
    public AjaxResult patchRemove(@RequestBody Long[] ids) {
        try {
            systemDictionaryDetailService.patchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return  AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试!");
        }
    }
}
